const gulp = require("gulp");
// const sass = require("gulp-sass")(require("sass")); //用于sass转换成css文件
// const cssmin = require("gulp-cssmin"); //进行压缩css文件：去空格
// const autoprefixer = require("gulp-autoprefixer"); //调用gulp-autoprefixer插件,为自动化处理css前缀的
var concat = require("gulp-concat"); //合并文件
var uglify = require("gulp-uglify"); //压缩js文件
var gzip = require("gulp-gzip"); //gzip包
var del = require("del");
var minifyCSS = require("gulp-minify-css");
console.log(process.env.NODE_ENV);
const paths = {
  styles: {
    src: "./src/styles/**/*.scss",
    dest: "./lib/styles/",
  },
  scripts: {
    src: "./src/js/**/*.js",
    dest: "./lib/js/",
  },
};
// 清空
const clean = () => {
  return del(["dist"]);
};
const font = () => {
  return gulp.src(["lib/layui/font/*"]).pipe(gulp.dest("dist/font"));
};
const html = () => {
  return gulp.src(["index_pub.html"]).pipe(concat("index.html")).pipe(gulp.dest("dist/"));
};
var cssMin = () => {
  return gulp
    .src([
      "lib/layui/css/layui.css",
      // "themes/theme06/common.css",
      "themes/theme06/layout.css",
      // "themes/theme06/page.css",
      // "themes/theme06/menu.css",
      // "themes/theme06/mindMap.css",
      "themes/theme06/mobile.css",
    ])
    .pipe(concat("index.css"))
    .pipe(minifyCSS())
    .pipe(gulp.dest("dist/css"));
};
//器件的js文件
var dist = "dist/resource";
const resource = () => {
  return gulp
    .src(["resource/partlib/*.js"])
    .pipe(concat("partlib.js"))
    .pipe(uglify())
    .pipe(gulp.dest(dist))
    .pipe(gzip()) //https://www.npmjs.com/package/gulp-gzip
    .pipe(gulp.dest(dist));
};
//第三方依赖项
const lib = () => {
  return gulp
    .src([
      "lib/easyui/jquery.min.js",
      "lib/easyui/jquery.easyui.min.js",
      "lib/layui/layui.js",
      // "lib/easyui/jquery.easyui.mobile.js",
      // "lib/canvasjs/jquery.canvasjs.min.js",
      // "lib/jquery-base64/base64.js",
      // "lib/upload/jquery.ui.widget.js",
      // "lib/upload/jquery.iframe-transport.js",
      // "lib/draw2d/lib/raphael.js",
      // "lib/draw2d/lib/canvg.js",
      // "lib/draw2d/lib/Class.js",
      "lib/draw2d/lib/shifty.js",
      // "lib/draw2d/lib/jquery.contextMenu.js",
      // "lib/draw2d/lib/rgbcolor.js",
      // "lib/draw2d/lib/StackBlur.js",
      // "lib/draw2d/lib/jquery.autoresize.js",
      // "lib/draw2d/lib/json2.js",
      // "lib/draw2d/lib/pathfinding-browser.min.js",
      // "lib/draw2d/lib/patched_canvg.js",
      "lib/draw2d/lib/patched_Class.js",
      "lib/draw2d/lib/patched_raphael_v1.js",
      "lib/draw2d/src/draw2d.js",
      "lib/state-machine/state-machine.min.js",
    ]) //模糊匹配  目录下所有 js 文件
    .pipe(concat("index.js"))
    .pipe(uglify())
    .pipe(gulp.dest("dist/lib"))
    .pipe(gzip()) //https://www.npmjs.com/package/gulp-gzip
    .pipe(gulp.dest("dist/lib"));
};
const baseExpand = () => {
  return gulp
    .src([
      //base
      "baseExpand/base/NsUtil.js",
      "baseExpand/base/UuidUtil.js",
      "baseExpand/base/Class.js",
      "baseExpand/base/Aggregation.js",
      "baseExpand/base/BaseObject.js",
      "baseExpand/base/Interface.js",
      "baseExpand/base/Property.js",
      "baseExpand/base/CompositeObject.js",
      //composite
      "baseExpand/composite/UIComposite.js",
      "baseExpand/composite/UICompositePanel.js",
      "baseExpand/composite/UICompositeDraw2dCanvas.js",

      "baseExpand/Listener/CommandStackEventListenerForViewPage.js",
      "baseExpand/Listener/SelectionChangeListener.js",
      "baseExpand/Listener/SelectionChangePublisher.js",
      "baseExpand/listener/EditorObjectSelectionChangeListener.js",
      "baseExpand/Listener/EditorObjectSelectionChangePublisher.js",
      "baseExpand/Listener/PartLibSelectionChangeListener.js",
      "baseExpand/Listener/PartLibSelectionChangePublisher.js",

      "baseExpand/messageHandler/MessageDefine.js",
      "baseExpand/messageHandler/MessageHandlerFactory.js",
      "baseExpand/messageHandler/RecvMessageHandler.js",
      "baseExpand/messageHandler/SendMessageHandler.js",
      "baseExpand/messageHandler/CmdMsgSender.js",
      "baseExpand/messageHandler/CviInterMsgSender.js",
      "baseExpand/messageHandler/ScenceMsgSender.js",
      "baseExpand/messageHandler/CmdReportMsgHandler.js",
      "baseExpand/messageHandler/CviInterMsgHandler.js",
      "baseExpand/messageHandler/EngineResultMsgHandler.js",

      "baseExpand/partlibTree/DataObject.js",
      "baseExpand/partlibTree/PartLibDataObject.js",
      "baseExpand/partlibTree/UsedPartLibDataObject.js",

      "baseExpand/draw2d/ApplicationEditor.js",
      "baseExpand/draw2d/GraphicalEditor.js",
      "baseExpand/draw2d/Draw2dGraphicalEditor.js",

      "baseExpand/draw2d/bridge/ADBridge.js",
      "baseExpand/draw2d/bridge/DABridge.js",

      "baseExpand/draw2d/commands/CommandAdd.js",
      "baseExpand/draw2d/commands/CommandAddJoint.js",
      "baseExpand/draw2d/commands/CommandAssignFigure.js",
      "baseExpand/draw2d/commands/CommandClockwise.js",
      "baseExpand/draw2d/commands/CommandConnect.js",
      "baseExpand/draw2d/commands/CommandCopy.js",
      "baseExpand/draw2d/commands/CommandCounterClockwise.js",
      "baseExpand/draw2d/commands/CommandCut.js",
      "baseExpand/draw2d/commands/CommandDelete.js",
      "baseExpand/draw2d/commands/CommandAddTheme.js",
      "baseExpand/draw2d/commands/CommandAddParaTheme.js",
      "baseExpand/draw2d/commands/CommandAddImg.js",
      "baseExpand/draw2d/commands/CommandAddParaImg.js",
      "baseExpand/draw2d/commands/CommandHideImg.js",
      "baseExpand/draw2d/commands/CommandShowImg.js",
      "baseExpand/draw2d/commands/CommandShowAllImg.js",
      "baseExpand/draw2d/commands/CommandHideAllImg.js",
      "baseExpand/draw2d/commands/CommandDeleteMulti.js",
      "baseExpand/draw2d/commands/CommandHorizontalFlip.js",
      "baseExpand/draw2d/commands/CommandMove.js",
      "baseExpand/draw2d/commands/CommandMoveVertex.js",
      "baseExpand/draw2d/commands/CommandMoveVertices.js",
      "baseExpand/draw2d/commands/CommandPaste.js",
      "baseExpand/draw2d/commands/CommandVerticalFlip.js",
      "baseExpand/draw2d/commands/CommandResize.js",

      "baseExpand/draw2d/editparts/Draw2dContext.js",
      "baseExpand/draw2d/editparts/AbstractEditPart.js",
      "baseExpand/draw2d/editparts/AbstractPortEditPart.js",
      "baseExpand/draw2d/editparts/CompositeEditPart.js",

      "baseExpand/draw2d/editparts/RootEditPart.js",
      "baseExpand/draw2d/editparts/DeviceEditPart.js",

      "baseExpand/draw2d/editparts/ConnectionEditPart.js",
      "baseExpand/draw2d/editparts/InputPortEditPart.js",
      "baseExpand/draw2d/editparts/OutputPortEditPart.js",
      "baseExpand/draw2d/editparts/HybridPortEditPart.js",
      "baseExpand/draw2d/editparts/JointEditPart.js",
      "baseExpand/draw2d/figures/XYAbsFigureLocator.js",
      "baseExpand/draw2d/figures/ConnectNodeLocator.js",
      "baseExpand/draw2d/figures/DeviceLabelLocator.js",
      "baseExpand/draw2d/figures/JointLocator.js",
      "baseExpand/draw2d/figures/ConnectNodeFigure.js",
      "baseExpand/draw2d/figures/DevicePortNumberLabelFigure.js",
      "baseExpand/draw2d/figures/DevicePortSymbolLabelFigure.js",
      "baseExpand/draw2d/figures/DeviceSymbolLabelFigure.js",
      "baseExpand/draw2d/figures/Canvas.js",
      "baseExpand/draw2d/figures/Connection.js",
      "baseExpand/draw2d/figures/ComponentFigure.js",
      "baseExpand/draw2d/figures/DeviceBodyImageFigure.js",
      "baseExpand/draw2d/figures/DeviceBoxFigure.js",
      "baseExpand/draw2d/figures/JointFigure.js",
      "baseExpand/draw2d/figures/LabelInplaceEditor.js",

      "baseExpand/draw2d/models/AbstractModel.js",
      "baseExpand/draw2d/models/AbstractPortModel.js",
      "baseExpand/draw2d/models/CompositeModel.js",
      "baseExpand/draw2d/models/RootModel.js",
      "baseExpand/draw2d/models/ConnectionModel.js",
      "baseExpand/draw2d/models/InputPortModel.js",
      "baseExpand/draw2d/models/OutputPortModel.js",
      "baseExpand/draw2d/models/HybridPortModel.js",
      "baseExpand/draw2d/models/JointModel.js",
      "baseExpand/draw2d/models/DeviceModel.js",
      "baseExpand/draw2d/models/DynamicModel.js",
      "baseExpand/draw2d/models/VirtualModel.js",
      "baseExpand/draw2d/models/DSVirtualModel.js",
      "baseExpand/draw2d/models/PmsModel.js",
      "baseExpand/draw2d/models/DeviceModelBuilder.js",

      "baseExpand/draw2d/handlers/ModelEventHandler.js",
      "baseExpand/draw2d/handlers/ModelEventHandlerAddChild.js",
      "baseExpand/draw2d/handlers/ModelEventHandlerAddConnection.js",
      "baseExpand/draw2d/handlers/ModelEventHandlerAddPort.js",
      "baseExpand/draw2d/handlers/ModelEventHandlerDimensionChanged.js",
      "baseExpand/draw2d/handlers/ModelEventHandlerFactory.js",
      "baseExpand/draw2d/handlers/ModelEventHandlerPositionChanged.js",
      "baseExpand/draw2d/handlers/ModelEventHandlerRemoveChild.js",
      "baseExpand/draw2d/handlers/ModelEventHandlerRemoveChildren.js",
      "baseExpand/draw2d/handlers/ModelEventHandlerRemoveConnection.js",
      "baseExpand/draw2d/handlers/ModelEventHandlerRemovePort.js",
      "baseExpand/draw2d/handlers/ModelEventHandlerUiPropertyChanged.js",
      "baseExpand/draw2d/handlers/ModelEventHandlerPropertyValueChanged.js",
      "baseExpand/draw2d/handlers/DeviceModelEventHandlerSetLabel.js",
      "baseExpand/draw2d/handlers/DeviceModelEventHandlerSetDevName.js",
      "baseExpand/draw2d/handlers/DeviceModelEventHandlerSetDevEngName.js",
      "baseExpand/draw2d/factory/PartFactory.js",
      "baseExpand/draw2d/factory/CircuitPartFactory.js",
      "baseExpand/draw2d/parser/CircuitParser.js",
      "baseExpand/draw2d/parser/ExperimentConverter.js",
      "baseExpand/draw2d/parser/NumberGenerator.js",
      "baseExpand/draw2d/parser/SimResult.js",

      "baseExpand/draw2d/request/ModelEventRequest.js",
      "baseExpand/draw2d/request/ModelEventRequestFactory.js",
      "baseExpand/draw2d/policies/KeyboardEditPolicy.js",
      "baseExpand/draw2d/policies/RectangleSelectionFeedbackPolicy.js",
      "baseExpand/draw2d/policies/OrthogonalConnectionCreatePolicy.js",
      "baseExpand/draw2d/policies/OrthogonalSelectionFeedbackPolicy.js",

      "baseExpand/draw2d/routers/InteractiveManhattanRouter.js",

      "baseExpand/context/Application.js",
      "baseExpand/context/AppWebSocket.js",
      "baseExpand/context/AppContext.js",
      "baseExpand/context/AppViewComponent.js",

      "baseExpand/newPart/FlowBox/TextFigure.js",
      "baseExpand/newPart/FlowBox/TextOvalFigure.js",
      "baseExpand/newPart/FlowBox/TextDiamondFigure.js",
      "baseExpand/newPart/FlowBox/TextModel.js",
      "baseExpand/newPart/FlowBox/TextModelJson.js",
      "baseExpand/newPart/FlowBox/TextModelOval.js",
      "baseExpand/newPart/FlowBox/TextModelDiamond.js",
      "baseExpand/newPart/FlowBox/TextModelJsonPara.js",
      "baseExpand/newPart/ConnectionModel.js",
      "baseExpand/newPart/Custom/CustomFigure.js",
      "baseExpand/newPart/Custom/CustomModel.js",
      "baseExpand/newPart/Custom/CustomImg.js",
      "baseExpand/newPart/Custom/PictureModelJson.js",
      "baseExpand/newPart/Custom/CustomImgPara.js",

      "baseExpand/newPart/Plus/PlusFigure.js",
      "baseExpand/newPart/Plus/PlusModel.js",
      "baseExpand/newPart/Plus/PlusModelJson.js",

      "baseExpand/newPart/Custom/CustomTextModel.js",
      "baseExpand/newPart/Custom/CustomTextFigure.js",
      "baseExpand/newPart/Custom/CustomTextJson.js",

      "baseExpand/viewComponents/AppExperimentCanvasComponent.js",

      //自己的扩展
      "main.js",
      "outer.js",
      "menuOpt.js",
      "propComp.js",
      "tabComp.js",
      // "experiment.js",
      "canvasScaleTranslate.js",
      "loading.js",
    ])
    .pipe(concat("index.js"))
    .pipe(
      uglify({
        output: {
          comments: false, //类型：Boolean 默认：true， 是否保留注释
        },
        compress: {
          drop_console: true, // 清除 console 语句
          drop_debugger: false, // 清除 debugger 语句
          pure_funcs: ["console.log"], // 移除console
        },
      })
    )
    .pipe(gulp.dest("dist/baseExpand")) //合并匹配到的 js 文件并命名为
    .pipe(gzip()) //https://www.npmjs.com/package/gulp-gzip
    .pipe(gulp.dest("dist/baseExpand"));
};
// gulp.task("default", function () {
//   console.log("default任务执行了");
// });
// gulp.task("default", gulp.parallel(resource)); //并行执行
gulp.task("default", gulp.series(clean, lib, baseExpand, cssMin, font, html)); //创建序列任务(任务执行完一个再一个)
